/*

Author   : chaos

FileName : stl_list.cpp

Date     : 17/08/17 09:59:11

*/
#include <iostream>
#include <iterator>
#include <list>
using namespace std;

#define Size 4

template <class T>

void print(list<T> & pri_con)
{
    if(pri_con.empty())
        cout << "Container is empty!" << endl;
    else{
        typename list<T>::iterator i;

        for( i = pri_con.begin();i != pri_con.end(); i++ )
        {
            cout << *i << " " ;
        }

        cout << endl;
    }
}
int main(int argc ,char *argv[])
{
    list<char> L;

    cout << "PUsh back 0,k,e and push front J ..." << endl;

    L.push_back('o');
    L.push_back('k');
    L.push_back('e');

    L.push_back('J');

    print(L);

    cout << "Pop front ..." << endl << "L :";
    L.pop_front();
    print(L);

    cout << "Pop back ..." << endl << "L : ";
    L.pop_back();
    print(L);

    cout << "First Element of L: " << L.front() << endl;

    cout << "Last Element of L: " << L.back() << endl;

    cout << "Maximum size of L: " << L.max_size() << endl;

    cout << "Insert array to list ..." << endl << "L2 :";
    char a[Size] = {'M','a','r','y'};
    list <char> L2;
    L2.insert(L2.begin(),a,a+Size);
    print(L2);

    cout << "Merge L and L2 ..." << endl << " L : ";
    L.merge(L2);
    print(L);
    cout << "L2 :";
    print(L2);
    cout << "Assign L to L2 ..." << endl << "L2 :" ;
    L2 = L;
    print(L2);

    cout << "Reverse L2 ..." << endl << "L2: ";
    L2.reverse();
    print(L2);

    cout << "Sort L2 ..." << endl << "L2 : ";
    L2.sort();
    print(L2);


    return 0;
}
